package com.uduew.sjd

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import com.uduew.sjd.config.AppConfig
import com.uduew.sjd.databinding.ActivityMainBinding
import com.uduew.sjd.ui.form.FormActivity
import com.uduew.sjd.ui.login.LoginActivity
import com.uduew.sjd.utils.MainHandler
import com.uduew.sjd.utils.PhotoImagePicker
import com.uduew.sjd.utils.StatusBarUtil
import com.uduew.utils.BarUtils

class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    @Deprecated("Deprecated in Java")
    override fun onActivityResult(
        requestCode: Int,
        resultCode: Int,
        data: Intent?
    ) {
        super.onActivityResult(requestCode, resultCode, data)
        PhotoImagePicker.getInstance().onActivityResult(this, requestCode, resultCode, data)
        supportFragmentManager
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        getDelegate().localNightMode = AppCompatDelegate.MODE_NIGHT_NO;
        if (supportActionBar != null) {
            supportActionBar?.hide()
        }
        BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
        StatusBarUtil.setStatusBar(this, false, 0, true)

        val lastActivityName = AppConfig.mConfigs.lastActivity().get()

        if (!lastActivityName.isNullOrEmpty()) {
            if (lastActivityName == FormActivity::class.java.name || lastActivityName == LoginActivity::class.java.name) {
                if (lastActivityName == FormActivity::class.java.name && !AppConfig.isLogin) return
                MainHandler.postDelay(1000) {
                    startActivity(Intent(this, Class.forName(lastActivityName)))
                }
            }
        }
    }
}